package encrypt

import (
	"crypto/md5"
	"crypto/sha1"
	"fmt"
)

func MD5(s string) string {
	bytes := []byte(s)
	hash := md5.Sum(bytes)
	md5Val := fmt.Sprintf("%x", hash)
	return md5Val
}

func Sha1(s string) []byte {
	input := []byte(s)
	h := sha1.New()
	h.Write(input)
	bs := h.Sum(nil)
	h.Reset()
	return bs
}

// MakeAES128 generate 128 bit AES key by input s
func MakeAES128(s string) []byte {
	num := 16
	bs := Sha1(s)
	keyBytes := make([]byte, num)
	copy(keyBytes, bs)
	return keyBytes
}

// MakeAES256 generate 256 bit AES key by input s
func MakeAES256(s string) []byte {
	num := 32
	bs := Sha1(s)
	keyBytes := make([]byte, num)
	copy(keyBytes, bs)
	return keyBytes
}
